package com.joysuch.wwyt.openapi.controllers.controllerV1;

import com.joysuch.wwyt.core.exception.ApiCoreException;
import com.joysuch.wwyt.openapi.controllers.controllerV1.req.ApiV1TokenReq;
import com.joysuch.wwyt.openapi.exception.ApiV1ExceptionCodeMsg;
import com.joysuch.wwyt.openapi.result.ApiV1Result;
import com.joysuch.wwyt.openapi.services.serviceV1.ApiV1TokenService;
import com.joysuch.wwyt.openapi.services.serviceV1.ApiV1TokenVerifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * @author: JamesZY
 * @date: 2021/9/7
 * @description:token接口
 */
@RestController
@RequestMapping("/api/v1")
public class ApiV1TokenController {
    @Autowired
    private ApiV1TokenService service;


    @PostMapping("/getToken")
    public ApiV1Result getToken(@RequestBody @Valid ApiV1TokenReq req,
                                HttpServletRequest request) {
        String token = null;
        try {
            token = service.getToken(req, request);
        } catch (ApiV1ExceptionCodeMsg e) {
            return ApiV1Result.error(e.getCode(), e.getMessage());
        }
        return ApiV1Result.success(token);
    }

}
